import store from '../store'
import api from '../http/api.js'
import {
	mapGetters,
	mapState
} from 'vuex';
export default {
	data() {
		return {
			share: {
				title: '',
				imageUrl: '',
				path: ''
			},
			status_name: 'loadmore', //loading nomore
			isLoading: false, //加载页-切换身份
		}
	},
	onShow() { //隐藏原生底部tabbar
		uni.hideTabBar();
	},
	onShareAppMessage(res) { //发送给朋友
		return {
			title: this.share.title,
			imageUrl: this.share.imageUrl,
			path: this.share.path,
		}
	},
	onShareTimeline(res) { //分享到朋友圈
		return {
			title: this.share.title,
			imageUrl: this.share.imageUrl,
			path: this.share.path,
			userInfo: '', //用户信息
		}
	},
	methods: {
		getUser() { //获取用户信息
			if (this.token) {
				api.getUser().then(res => {
					if (res.code == 1) {
						store.commit('saveIdentity', res.data.userInfo.group_id)
						store.commit('saveUserInfo', res.data.userInfo)
					}
				})
			}
		}
	},
	computed: {
		...mapState({
			token: state => state.token,
			identity: state => state.identity,
			user: state => state.userInfo,
		}),
	},
	watch: {
		identity() {
			this.isLoading = true
			setTimeout(() => {
				this.isLoading = false
				uni.switchTab({
					url: '/pages/share/index/index'
				})
			}, 2500)
		}
	}
}
